package LeetCode.NumOffer;

/**
 * @author lumin
 * @date 2022/05/13 12:18
 **/
public class NumOffer45 {
    public String minNumber(int[] nums) {
        String str = "";
        if(nums.length == 0){
            return str;
        }
        String[] num = new String[nums.length];
        if(nums[0] == 0){
            for (int i = 0; i < nums.length - 1; i++) {
                num[i] = String.valueOf(nums[i + 1]);
            }
        }else{
            for (int i = 0; i < nums.length; i++) {
                num[i] = String.valueOf(nums[i]);
            }
        }

        if(num.length == 1){
            str = String.valueOf(nums[0]);
            return str;
        }
        str = num[0] + num[1];
        if(str.compareTo(num[1] + num[0]) > 0){
            str = num[1] + num[0];
        }else{
            str = num[1] + num[1];
        }
        for (int i = 1; i + 1 < num.length; i++) {
            if((str + num[i + 1]).compareTo(num[i + 1] + str) > 0){
                str = num[i + 1] + str;
            }else{
                str += num[i + 1];
            }
        }
        return str;
    }
}